<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/payment.class.php");
	include("includes/class/comment.class.php");
	include("includes/class/case.class.php");
	
	$payment = new Payment();
	$comment = new Comment();
	$myCase= new MyCase();
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;	
	
	$case_code =  $_GET['case_code']; 
	
	$my_case = $myCase->getCase($case_code);
	$pay_balance = $payment->getPayBalanceDue($case_code);
	
	if(isset($_POST['add']) && $_POST['add'] == 1){
		$pay_balance = $payment->getPayBalanceDue($_POST['case_code']);
		
		$data->case_code			= $_POST['case_code'];
		$data->cli_code   			= $my_case->cli_code;
		$data->use_code 			= $_SESSION['use_code'];
		$data->pay_value 			= trim(mysql_real_escape_string($_POST['pay_value']));		
		$data->pay_balance 			= $pay_balance-$data->pay_value;
		$data->pay_comment 			= trim(mysql_real_escape_string($_POST['pay_comment']));
		
		if ($payment->addPayment($data)){
			$msg_info = true;
				$_SESSION["msg_cool"] .= 'You added the Payment Type successfully..!!!<br />';
			echo "<script> window.location.href='listPayment.php?show_msg=2'</script>";
		}
		else{
			$msg_error = true;
				$_SESSION["msg_cool"] .= 'It could not be added the Payment... Sorry..!!!<br />';
			echo "<script> window.location.href='listPayment.php?show_msg=1'</script>";
		}
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;	
	
		
?>